#include "stdafx.h"

#include "resource.h"

#include "waconsts.h"
#include "eeg_exceptions.h"
#include "datastore.h"
#include "waitbox.h"
#include "utilities.h"
#include "eeg_exceptions.h"

#include "dsacalculator.h"
#include "dsasingleGraph.h"

#include "dsagraphview.h"

void CDSAGraphView::Draw(HDC hdc){
	RECT rcBounds;
	GetClientRect(&rcBounds);
	//rcBounds.bottom-=TOOLBAR_HEIGHT;
	Rect rc(rcBounds.left,rcBounds.top,rcBounds.right,rcBounds.bottom);
	Bitmap bmp(rcBounds.right,rcBounds.bottom);//memory bitmap
	Graphics graphics(hdc); 

	FontFamily  fontFamily(_T("Times New Roman"));
	Font        font(&fontFamily, 24, FontStyleRegular, UnitPixel);
	SolidBrush  solidBrush(Color(255, 255, 255, 255));


	// Create a Graphics object that is associated with the image.
	Graphics* graph = Graphics::FromImage(&bmp);

	if(!calc){
		MessageBox(_T("No input!"));
		DestroyWindow();
	}
	//graph->Clear(BG_COLOR);
	UINT gw = rc.Width, gh= (rc.Height- 2*MARGIN_WIDTH)/subg.size();
	if(calc->isReady())
	{

		for(size_t i=0;i<subg.size();i++)
		{
			//DSASingleGraph sg(calc, subg[i]);
			//Rect rectOneGraph(MARGIN_WIDTH,MARGIN_WIDTH, );
			subg[i].SetGraphRect(0, MARGIN_WIDTH + gh*i, gw, gh);
			subg[i].Draw(graph);
		}
	}else{
		
		graph->DrawString(_T("Data is NOT available!"),-1,&font,PointF(0.0,0.0),&solidBrush);
	}

	graphics.DrawImage(&bmp,PointF(0,0));
	SAFE_DELETE(graph);

}